class Solution {
public:
    int findLongestChain(vector<vector<int>>& pairs) {
        int n = pairs.size();
        vector<int> dp(n,1);
        sort(pairs.begin(),pairs.end());
        int ret=1;
        for(int i=1;i<n;i++)
        {
            for(int j=0;j<i;j++)
            {
                int b = pairs[j][1];
                int c = pairs[i][0];
                if(b<c)
                {
                    dp[i] = max(dp[j]+1,dp[i]);
                }
            }
            ret = max(ret,dp[i]);
        }
        return ret;
    }
};